package com.framework.admin.schedule.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.framework.admin.schedule.entity.SysJobLog;
import com.framework.admin.schedule.param.JobLogParam;
import com.framework.admin.schedule.service.ISysJobLogService;
import com.framework.common.domain.ResultData;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/jobLog")
public class JobLogController {
    @Autowired
    private ISysJobLogService jobLogService;

    @ApiOperation("获取所有的任务")
    @PostMapping(value = "/list")
    public ResultData listJobs(@RequestBody JobLogParam param) {
        Page request = Page.of(param.getPageNo(), param.getPageSize());
        Page<SysJobLog> users = jobLogService.listJobs(param, request);
        return ResultData.data(users);
    }
    @ApiOperation("获取单个任务")
    @PostMapping(value = "/clean")
    public ResultData getJob() {
        jobLogService.cleanJobLog();
        return ResultData.success();
    }

    @ApiOperation("删除任务")
    @PostMapping(value = "/delete/{ids}")
    public ResultData deleteJob(@PathVariable String ids) {
        String[] idList = ids.split(",");
        Long[] list = new Long[idList.length];
        for (int i = 0; i < idList.length; i++) {
            list[i] = Long.valueOf(idList[i]);   //依次遍历赋值
        }
        jobLogService.deleteJobLogByIds(list);
        return ResultData.success();
    }


}
